package com.lc1993929.mr.rating;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import org.springframework.beans.BeanUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by LiuChang on 2017/11/14/014.
 */
public class UserRatingTopNReducer extends Reducer<Text, RateBean, Text, RateBean> {
    @Override
    protected void reduce(Text key, Iterable<RateBean> values, Context context) throws IOException, InterruptedException {
        int topn = context.getConfiguration().getInt("user.rate.topn", 5);

        List<RateBean> beanList = new ArrayList<>();
        values.forEach(rateBean -> {
            RateBean newBean = new RateBean();
            BeanUtils.copyProperties(rateBean, newBean);
            beanList.add(newBean);
        });
        //将本user 的评分数据按评分大小倒序培训
        Collections.sort(beanList);

        //    输出前N个评分数据
        for (int i = 0; i < topn; i++) {


        }
    }
}
